From a7361f672b501033720f54def4c249ef1abf1799 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Tue, 28 Feb 2006 18:59:24 +0100 Subject: [PATCH] Allow netback to be built as a module. From: Jan Beulich Signed-off-by: Keir Fraser --- buildconfigs/linux-defconfig_xen0_x86_32 | 1 + buildconfigs/linux-defconfig_xen0_x86_64 | 1 + buildconfigs/linux-defconfig_xen_x86_32 | 1 + buildconfigs/linux-defconfig_xen_x86_64 | 1 + linux-2.6-xen-sparse/drivers/xen/Kconfig | 10 ++++++- .../drivers/xen/core/skbuff.c | 1 + .../drivers/xen/netback/Makefile | 5 +++- .../drivers/xen/netback/loopback.c | 29 +++++++++++++++++++ .../drivers/xen/netback/netback.c | 4 +++ 9 files changed, 51 insertions(+), 2 deletions(-) diff --git a/buildconfigs/linux-defconfig_xen0_x86_32 b/buildconfigs/linux-defconfig_xen0_x86_32 index f9138569bf..f3ea4053b5 100644 --- a/buildconfigs/linux-defconfig_xen0_x86_32 +++ b/buildconfigs/linux-defconfig_xen0_x86_32 @@ -1320,6 +1320,7 @@ CONFIG_XEN_BLKDEV_BACKEND=y # CONFIG_XEN_BLKDEV_TAP_BE is not set CONFIG_XEN_NETDEV_BACKEND=y # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set +CONFIG_XEN_NETDEV_LOOPBACK=y # CONFIG_XEN_TPMDEV_BACKEND is not set CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y diff --git a/buildconfigs/linux-defconfig_xen0_x86_64 b/buildconfigs/linux-defconfig_xen0_x86_64 index e6563cb32b..7baeb3d47e 100644 --- a/buildconfigs/linux-defconfig_xen0_x86_64 +++ b/buildconfigs/linux-defconfig_xen0_x86_64 @@ -1244,6 +1244,7 @@ CONFIG_XEN_BLKDEV_BACKEND=y # CONFIG_XEN_BLKDEV_TAP_BE is not set CONFIG_XEN_NETDEV_BACKEND=y # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set +CONFIG_XEN_NETDEV_LOOPBACK=y # CONFIG_XEN_TPMDEV_BACKEND is not set CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y diff --git a/buildconfigs/linux-defconfig_xen_x86_32 b/buildconfigs/linux-defconfig_xen_x86_32 index db03a3a82a..49208186f9 100644 --- a/buildconfigs/linux-defconfig_xen_x86_32 +++ b/buildconfigs/linux-defconfig_xen_x86_32 @@ -2986,6 +2986,7 @@ CONFIG_XEN_BLKDEV_BACKEND=y # CONFIG_XEN_BLKDEV_TAP_BE is not set CONFIG_XEN_NETDEV_BACKEND=y # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set +CONFIG_XEN_NETDEV_LOOPBACK=y # CONFIG_XEN_TPMDEV_BACKEND is not set CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y diff --git a/buildconfigs/linux-defconfig_xen_x86_64 b/buildconfigs/linux-defconfig_xen_x86_64 index 0f70c8a940..85314f98d3 100644 --- a/buildconfigs/linux-defconfig_xen_x86_64 +++ b/buildconfigs/linux-defconfig_xen_x86_64 @@ -2656,6 +2656,7 @@ CONFIG_XEN_BLKDEV_BACKEND=y # CONFIG_XEN_BLKDEV_TAP_BE is not set CONFIG_XEN_NETDEV_BACKEND=y # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set +CONFIG_XEN_NETDEV_LOOPBACK=y # CONFIG_XEN_TPMDEV_BACKEND is not set CONFIG_XEN_BLKDEV_FRONTEND=y CONFIG_XEN_NETDEV_FRONTEND=y diff --git a/linux-2.6-xen-sparse/drivers/xen/Kconfig b/linux-2.6-xen-sparse/drivers/xen/Kconfig index 046de51a21..2cd2d937ea 100644 --- a/linux-2.6-xen-sparse/drivers/xen/Kconfig +++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig @@ -89,7 +89,7 @@ config XEN_BLKDEV_TAP_BE modified to use grant tables. config XEN_NETDEV_BACKEND - bool "Network-device backend driver" + tristate "Network-device backend driver" default y help The network-device backend driver allows the kernel to export its @@ -109,6 +109,14 @@ config XEN_NETDEV_PIPELINED_TRANSMITTER are unsure; or if you experience network hangs when this option is enabled; then you must say N here. +config XEN_NETDEV_LOOPBACK + tristate "Network-device loopback driver" + depends on XEN_NETDEV_BACKEND + default y + help + A two-interface loopback device to emulate a local netfront-netback + connection. + config XEN_TPMDEV_BACKEND bool "TPM-device backend driver" default n diff --git a/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c b/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c index c90fc20b56..c12362ded7 100644 --- a/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c +++ b/linux-2.6-xen-sparse/drivers/xen/core/skbuff.c @@ -16,6 +16,7 @@ /* Referenced in netback.c. */ /*static*/ kmem_cache_t *skbuff_cachep; +EXPORT_SYMBOL(skbuff_cachep); #define MAX_SKBUFF_ORDER 4 static kmem_cache_t *skbuff_order_cachep[MAX_SKBUFF_ORDER + 1]; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/Makefile b/linux-2.6-xen-sparse/drivers/xen/netback/Makefile index fd75bff6ab..d5d232837e 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/Makefile +++ b/linux-2.6-xen-sparse/drivers/xen/netback/Makefile @@ -1,2 +1,5 @@ +obj-$(CONFIG_XEN_NETDEV_BACKEND) := netbk.o +obj-$(CONFIG_XEN_NETDEV_LOOPBACK) += netloop.o -obj-y := netback.o xenbus.o interface.o loopback.o +netbk-y := netback.o xenbus.o interface.o +netloop-y := loopback.o diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c b/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c index 03e6c29729..a5a11cc55e 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/loopback.c @@ -178,6 +178,23 @@ static int __init make_loopback(int i) return err; } +static void __init clean_loopback(int i) +{ + struct net_device *dev1, *dev2; + char dev_name[IFNAMSIZ]; + + sprintf(dev_name, "vif0.%d", i); + dev1 = dev_get_by_name(dev_name); + sprintf(dev_name, "veth%d", i); + dev2 = dev_get_by_name(dev_name); + if (dev1 && dev2) { + unregister_netdev(dev2); + unregister_netdev(dev1); + free_netdev(dev2); + free_netdev(dev1); + } +} + static int __init loopback_init(void) { int i, err = 0; @@ -191,6 +208,18 @@ static int __init loopback_init(void) module_init(loopback_init); +static void __exit loopback_exit(void) +{ + int i; + + for (i = nloopbacks; i-- > 0; ) + clean_loopback(i); +} + +module_exit(loopback_exit); + +MODULE_LICENSE("Dual BSD/GPL"); + /* * Local variables: * c-file-style: "linux" diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index 3b6de4612d..64173fae5d 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -809,6 +809,8 @@ static int __init netback_init(void) &netif_be_dbg); #endif + __unsafe(THIS_MODULE); + return 0; } @@ -820,6 +822,8 @@ static void netback_cleanup(void) module_init(netback_init); module_exit(netback_cleanup); +MODULE_LICENSE("Dual BSD/GPL"); + /* * Local variables: * c-file-style: "linux" -- 2.30.2